<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 商品列表 -->
    <el-card class="box-card">
      <!-- 搜索框 -->
      <template>
      <el-input style="width: 35%" placeholder="接口有问题写不了" class="input-with-select" clearable>
      <el-button slot="append" icon="el-icon-search"></el-button></el-input>
      </template>
      <!-- 订单表格 -->
      <el-table
      border
      stripe
      :data="ordersList"
      style="width: 100%">
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="order_number" label="订单号"></el-table-column>
      <el-table-column prop="order_price" label="订单价格"></el-table-column>
      <el-table-column prop="pay_status" label="是否付款">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.pay_status === '0'">未付款</el-tag>
          <el-tag type="success" v-else>已付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货"></el-table-column>
      <el-table-column label="下单时间">
        <template slot-scope="scope">
          {{ scope.row.create_time | formatTime }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="editAddressFlag = true"></el-button>
          <el-button type="success" size="mini" icon="el-icon-location" @click="showExpress(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryData.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryData.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    </el-card>
    <!-- 展示修改对话框 -->
    <el-dialog
      title="提示"
      :visible.sync="editAddressFlag"
      width="50%">
      <el-form ref="form" :model="cityForm" label-width="80px">
        <el-form-item label="省市区/县:">
          <el-cascader
            style="width: 450px"
            clearable
            v-model="cityValue"
            :options="cityData"
            @change="handleChange"></el-cascader>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editAddressFlag = false">取 消</el-button>
        <el-button type="primary" @click="editAddressFlag = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 展示物流对话框 -->
    <el-dialog
      title="查看物流信息"
      :visible.sync="showExpressFlag"
      width="35%">
      <el-timeline :reverse="true">
        <el-timeline-item
          v-for="(item, index) in ExpressList"
          :key="index"
          :timestamp="item.time">
          {{item.content}}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showExpressFlag = false">取 消</el-button>
        <el-button type="primary" @click="showExpressFlag = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      // 查询参数
      queryData: {
        pagenum: 1,
        pagesize: 10
      },
      // 表格数据
      ordersList: [],
      // 总条数
      total: 0,
      editAddressFlag: false,
      cityForm: {},
      cityValue: [],
      cityData,
      showExpressFlag: false,
      ExpressList: []
    }
  },

  created () {
    this.getOrdersList()
  },

  methods: {
    // 获取数据
    async getOrdersList () {
      const { data: res } = await this.$axios.get('orders', { params: this.queryData })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.ordersList = res.data.goods
      this.total = res.data.total
    },

    // 条数发生变化
    handleSizeChange (val) {
      this.queryData.pagesize = val
      this.getOrdersList()
    },

    // 页码发生变化
    handleCurrentChange (val) {
      this.queryData.pagenum = val
      this.getOrdersList()
    },

    handleChange () {
      console.log(this.cityValue)
    },
    // 显示物流事件
    async showExpress (row) {
      this.showExpressFlag = true
      const { data: res } = await this.$axios.get('http://localhost:8080/api/express')
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.ExpressList = res.data
      console.log(res)
    }
  }
}
</script>

<style scoped lang='less'>

</style>
